package com.demo.java.OD401_450.OD412;

import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【开源项目热榜(C&D卷)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146254125
 */
public class OdMain {
    static class Project implements Comparable<Project> {
        String name;
        int watch, star, fork, issue, mr;
        int weightWatch, weightStar, weightFork, weightIssue, weightMR;

        public Project(String name, int watch, int star, int fork, int issue, int mr,
                       int weightWatch, int weightStar, int weightFork, int weightIssue, int weightMR) {
            this.name = name;
            this.watch = watch;
            this.star = star;
            this.fork = fork;
            this.issue = issue;
            this.mr = mr;
            this.weightWatch = weightWatch;
            this.weightStar = weightStar;
            this.weightFork = weightFork;
            this.weightIssue = weightIssue;
            this.weightMR = weightMR;
        }

        public int calculateHeat() {
            // 计算热度值
            return watch * weightWatch + star * weightStar + fork * weightFork + issue * weightIssue + mr * weightMR;
        }

        @Override
        public int compareTo(Project other) {
            // 计算热度差异
            int heatDiff = other.calculateHeat() - this.calculateHeat();
            if (heatDiff == 0) {
                // 如果热度相同，则按项目名称的字典序升序排列
                return this.name.toLowerCase().compareTo(other.name.toLowerCase());
            }
            return heatDiff;  // 返回热度差异
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();  // 读取项目的数量
        scanner.nextLine();  // 读取换行符

        // 读取各项权重
        int weightWatch = scanner.nextInt();
        int weightStar = scanner.nextInt();
        int weightFork = scanner.nextInt();
        int weightIssue = scanner.nextInt();
        int weightMR = scanner.nextInt();
        scanner.nextLine();  // 读取换行符

        List<Project> projects = new ArrayList<>();

        // 读取每个项目的数据并创建Project对象
        for (int i = 0; i < n; i++) {
            String name = scanner.next();
            int watch = scanner.nextInt();
            int star = scanner.nextInt();
            int fork = scanner.nextInt();
            int issue = scanner.nextInt();
            int mr = scanner.nextInt();

            projects.add(new Project(name, watch, star, fork, issue, mr, weightWatch, weightStar, weightFork, weightIssue, weightMR));
        }

        // 对项目按热度进行排序
        Collections.sort(projects);

        // 输出排序后的项目名称
        for (Project project : projects) {
            System.out.println(project.name);
        }
    }
}
